<div class="content-wrapper" [@routerTransition]>
    <sub-header idName="Administration.Roles" [title]="'Roles' | localize" [description]="'RolesHeaderInfo' | localize">
        <div role="actions">
            <button (click)="createRole()" *ngIf="'Pages.Administration.Roles.Create' | permission"
                class="btn btn-primary blue"><i class="fa fa-plus"></i> {{"CreateNewRole" | localize}}</button>
        </div>
    </sub-header>
    <section class="content d-flex flex-column flex-column-fluid">
        <div [class]="containerClass">
            <div class="card card-custom">
                <div class="card-body">
                    <div class="form">
                        <div class="row">
                            <div class="col-xl-6">
                                <div class="form-group">
                                    <permission-combo [(ngModel)]="permissionSelected" (change)="getRoles()"></permission-combo>
                                </div>
                            </div>
                            <div class="col-xl-6 text-right">
                                <div class="form-group">
                                    <menu-permission-combo [(ngModel)]="menuPermissionSelected" (change)="getRoles()"></menu-permission-combo>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row align-items-center">
                        <!--<Primeng-TurboTable-Start>-->
                        <div class="col primeng-datatable-container" [busyIf]="primengTableHelper.isLoading">
                            <p-table #dataTable (onLazyLoad)="getRoles()" [value]="primengTableHelper.records"
                                rows="{{primengTableHelper.defaultRecordsCountPerPage}}" [paginator]="false"
                                [lazy]="true" [responsive]="primengTableHelper.isResponsive">

                                <ng-template pTemplate="header">
                                    <tr>
                                        <th style="width: 130px"
                                            [hidden]="!(['Pages.Administration.Roles.Edit', 'Pages.Administration.Roles.Delete'] | permissionAny)">
                                            {{'Actions' | localize}}</th>
                                        <th>{{'RoleName' | localize}}</th>
                                        <th>{{'Order' | localize}}</th>
                                        <th>{{'CreationTime' | localize}}</th>
                                    </tr>
                                </ng-template>

                                <ng-template pTemplate="body" let-record="$implicit">
                                    <tr>
                                        <td
                                            [hidden]="!((['Pages.Administration.Roles.Edit', 'Pages.Administration.Roles.Delete'] | permissionAny) || entityHistoryEnabled)">
                                            <div class="btn-group" dropdown placement="bottom left">
                                                <button id="dropdownButton" type="button" class="btn btn-primary btn-xs2 dropdown-toggle blue" dropdownToggle aria-controls="dropdownMenu">
                                                    <i class="fa fa-cog"></i><span class="caret"></span>
                                                    {{"Actions" | localize}}
                                                </button>
                                                <ul id="dropdownMenu" class="dropdown-menu" role="menu" *dropdownMenu aria-labelledby="dropdownButton">
                                                    <li *ngIf="'Pages.Administration.Roles.Edit' | permission" role="menuitem">
                                                        <a class="dropdown-item" href="javascript:;"
                                                        (click)="createOrEditRoleModal.show(record.id)">{{'Edit' | localize}}</a>
                                                    </li>
                                                    <li *ngIf="!record.isStatic && ('Pages.Administration.Roles.Delete' | permission)" role="menuitem">
                                                        <a class="dropdown-item" href="javascript:;"                                                        
                                                        (click)="deleteRole(record)">{{'Delete' | localize}}</a>
                                                    </li>
                                                    <li *ngIf="entityHistoryEnabled" role="menuitem">
                                                        <a class="dropdown-item" href="javascript:;"
                                                        (click)="showHistory(record)">{{'History' | localize}}</a>
                                                    </li>
                                                </ul>
                                            </div>
                                        </td>
                                        <td>
                                            <span class="p-column-title">{{'RoleName' | localize}}</span>
                                            <span>
                                                <a href="javascript:" (click)="createOrEditRoleModal.show(record.id)">{{record.displayName}}</a>
                                                &nbsp;
                                                <span *ngIf="record.isStatic"
                                                      class="label bg-info"
                                                      data-toggle="tooltip" title="{{'StaticRole_Tooltip' | localize}}"
                                                      data-placement="top">
                                                    {{'Static' | localize}}
                                                </span>
                                                &nbsp;
                                                <span *ngIf="record.isDefault"
                                                      class="label bg-secondary"
                                                      data-toggle="tooltip"
                                                      title="{{'DefaultRole_Description' | localize}}"
                                                      data-placement="top">
                                                    {{'Default' | localize}}
                                                </span>
                                            </span>
                                        </td>
                                        <td>
                                            <span class="p-column-title"> {{'Order' | localize}}</span>
                                            {{record.order}}
                                        </td>
                                        <td>
                                            <span class="p-column-title">{{'CreationTime' | localize}}</span>
                                            {{record.creationTime | luxonFormat:'F'}}
                                        </td>
                                    </tr>
                                </ng-template>
                            </p-table>
                            <div class="primeng-no-data" *ngIf="primengTableHelper.totalRecordsCount == 0">
                                {{'NoData' | localize}}
                            </div>
                            <div class="ui-table-footer">
                            </div>
                        </div>
                        <!--<Primeng-TurboTable-End>-->
                    </div>
                </div>
            </div>
        </div>

        <createOrEditRoleModal #createOrEditRoleModal (modalSave)="getRoles()"></createOrEditRoleModal>
        <entityTypeHistoryModal #entityTypeHistoryModal></entityTypeHistoryModal>
    </section>
</div>
